package com.luocj.muke.demo.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.luocj.muke.demo.R;
import com.luocj.muke.demo.utils.GridItemDecoration;
import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration;
import com.yqritc.recyclerviewflexibledivider.VerticalDividerItemDecoration;

import java.util.ArrayList;

public class DiversActivity extends AppCompatActivity {

    private RecyclerView recyclerview;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_divers);
        initView();
    }

    private void initView() {
        recyclerview = findViewById(R.id.recyclerview);
        GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 4);

//        recyclerview.addItemDecoration(new HorizontalDividerItemDecoration.Builder(this).build());
//        recyclerview.addItemDecoration(new VerticalDividerItemDecoration.Builder(this).build());
        GridItemDecoration divider = new GridItemDecoration.Builder(DiversActivity.this)
                .setHorizontalSpan(R.dimen.common_vew_column_padding)
                .setVerticalSpan(R.dimen.common_vew_raw_padding)
                .setColorResource(R.color.orange)
                .setShowLastLine(false)
                .build();
        recyclerview.addItemDecoration(divider);
        recyclerview.setLayoutManager(gridLayoutManager);

        DiverAdapter diverAdapter = new DiverAdapter(R.layout.item_text, getDatas());
        recyclerview.setAdapter(diverAdapter);

    }

    private ArrayList<String> getDatas() {
        ArrayList<String> strings = new ArrayList<>();
        strings.add("排名");
        strings.add("分公司");
        strings.add("业绩");
        strings.add("备注");
        for (int i = 0; i < 40; i++) {
            strings.add(i + "");
        }
        return strings;
    }

    private class DiverAdapter extends BaseQuickAdapter<String, BaseViewHolder> {

        public DiverAdapter(int item_text, ArrayList<String> datas) {
            super(item_text, datas);
        }

        @Override
        protected void convert(BaseViewHolder holder, String item) {
            holder.setText(R.id.tv_text, item);
        }
    }
}
